{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1167
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	i,n,q,t,m:longint;
	a:array[0..100010] of longint;
 
procedure siftdown(i:longint);
 
var 
  j,t:longint;
 
begin
while 2*i<=n do begin
  j:=i;
	if a[2*i]>a[j] then j:=2*i;
	if (2*i+1<=n) and (a[2*i+1]>a[j]) then j:=2*i+1;
  if i<j then begin
    t:=a[i];
    a[i]:=a[j];
    a[j]:=t;
    i:=j;
	end else 
	if i=j then break;
end;
if n=0 then write('0 ') else write(i,' ');
end;
 
procedure siftup(i:longint);
 
var 
  t:longint;
 
begin
while (i>1) and (a[i div 2]<a[i]) do begin
  t:=a[i];
  a[i]:=a[i div 2];
  a[i div 2]:=t;
  i:=i div 2;
end;
writeln(i);
end;
 
procedure insert(v:longint);
begin
inc(n);
a[n]:=v;
siftup(n);
end;
 
function ex_max:longint;
begin
result:=a[1];
a[1]:=a[n];
dec(n);
siftdown(1);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(m,q);
n:=0;
for i:=1 to q do begin
	read(t);
	if t=1 then begin
		if n=0 then writeln(-1) else writeln(ex_max);
	end else begin
		read(t);
		if m=n then writeln(-1) else insert(t);
	end;
end;
for i:=1 to n do
	write(a[i],' ');
end.